<?

class Config_model extends CI_Model
{	
	function __construct()
	{
		parent::__construct();
		
	}

	function set_item($key, $val)
	{
		$this->db->where('name', $key)->set('value', $val)->update('config');
	}
	function get_config()
	{
		$items = array();
		$db_items = $this->db->get('config')->result_array();
		$this->load->lang('db_config');
		$modules = $this->config->item('modules');
		
		foreach($db_items as $db_item)
		{
			$items[] = @array_merge($db_item, array('friendly_name' => $db_item[ $lang['name'] ]['friendlyname'], 'description' => $db_item[ $lang['name'] ]['description']));
		}
	
	}
	
	function get_by_categorie($return_non_editable = FALSE)
	{
		$items = array();
		$lang = array();
		
		$modules = config_item('modules');
		$lang = $this->load->language('database_config', NULL, TRUE);
		foreach($modules as $module)
			$lang = array_merge($lang, $this->load->language($module.'/db_config', NULL, TRUE));
		
		if(!$return_non_editable)
			$this->db->where('editable !=', 0);
			
		$db_items = $this->db->get('config')->result_array();
		foreach($db_items as $item)
		{
			if(isset($lang[ $item['name'] ]['friendly_name']))
				$item['friendly_name'] = $lang[ $item['name'] ]['friendly_name'];
				
			if(isset($lang[ $item['name'] ]['description']))
				$item['description'] = $lang[ $item['name'] ]['description'];
							
			$items[ $item['categorie'] ][] = $item;
		}
		
		return $items;
	}
}

?>